package com.zx.cashiersystem.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.zx.cashiersystem.adapter.OrderAdapter;
import com.zx.cashiersystem.cashiersystem.R;
import com.zx.cashiersystem.entitys.OrderInfo;
import com.zx.cashiersystem.mvp.presenter.OrderLeftPrestener;
import com.zx.cashiersystem.mvp.view.OrderLeftView;
import com.zx.cashiersystem.utils.ContantsIntent;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/2/7.
 * 未完成的订单页面---只有堂吃
 */

public class OrderActivity extends BaseActivity implements OrderLeftView {
    private ListView listView;
    private OrderAdapter adapter;
    private List<OrderInfo> list;
    private OrderLeftPrestener prestener;
    private OrderInfo orderInfo = new OrderInfo();;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order);
    }

    @Override
    protected void initView() {
        listView = (ListView) findViewById(R.id.listView);

    }

    @Override
    protected void initEvent() {
        prestener = new OrderLeftPrestener(this, context);
        final Intent intent = new Intent(this, PayActivity.class);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                adapter.setSelect(position);
                //跳转该笔订单的结算页面
                intent.putExtra(ContantsIntent.ORDERINFO,list.get(position));
                startActivity(intent);
            }
        });

    }

    @Override
    protected void initData() {
        initViewList();
//        prestener.getFromNet();
        getData();
    }

    private void getData() {

        orderInfo.setOrderid("111");
        orderInfo.setTotalprice(100.9);
        for (int i = 0; i < 10; i++) {
            list.add(orderInfo);
        }
    }

    private void initViewList() {
        if (list == null) {
            list = new ArrayList();
        }
        if (adapter == null) {
            adapter = new OrderAdapter(context, list);
            listView.setAdapter(adapter);
        } else {
            adapter.notifyDataSetChanged();
        }
    }

    @Override
    public void onFial(String str) {

    }

    @Override
    public void onSuccess(List<OrderInfo> list) {
        initViewList();
        showOrderList(list);

    }

    @Override
    public void showOrderList(List<OrderInfo> list) {

    }
}
